# -*- coding:utf-8 -*-
# 字典类型
scores = {
    'Li': 10,
    'Han': 90
}

# 按照键赋值
scores['Liu'] = 80
print(scores)  # {'Liu': 80, 'Han': 90, 'Li': 100} 输出顺序

# 删除元素
del scores['Liu']
print(scores)  # {'Han': 90, 'Li': 10}

# 获取所以键
print(scores.keys(), type(scores.keys()))  # (['Han', 'Li'], <type 'list'>)
print(list(scores.keys()), type(list(scores.keys())))  # (['Han', 'Li'], <type 'list'>)

# 键值对列表转换为字典
print(dict([('G', 100), ('Z', 90)]))  # {'Z': 90, 'G': 100}

#
print(dict(G=10, Z=8))  # {'Z': 8, 'G': 10}

# 字典的循环
info = {'name': 'GC', 'age': 19}
print(info.items(), type(
    info.items()))  # [('age', 19), ('name', 'GC')], <type 'list'>) items方法 items(self) -> list[Tuple[_KT, _VT_co]]
for k, v in info.items():
    print(k, v)  # ('age', 19) ('name', 'GC')

# 列表循环
lists = ['a', 'b']
print(type(enumerate(lists)), enumerate(lists))  # <type 'enumerate'>  <enumerate object at 0x10db55550>)
for i, v in enumerate(lists):
    print(i, v)  # (0, 'a') # (1, 'b')

# 循环多个序列
names = ['GC', 'XX', 'LC']
ages = [10, 20, 30, 40]

for name, age in zip(names, ages):
    print(name, age) # ('GC', 10) ('XX', 20) ('LC', 30) 只进行了3此循环
